In Dojo, there are two ways.
1. A Dojo button's onclick attribute takes the name of the event handler method. You don't actually call the method like you do for a regular DOM button. 2. Second, the event handler method gets only one parameter – the Event object. Let's have a look at an example. The event handler is registered as follows:
<button dojoType="dijit.form.Button" onclick="showEvent">OK</button>
Register event handlers for the buttons as shown below.
The event handler method looks like this: function showEvent(theEvent) { alert("Event " + theEvent.type); } function showEvent(theEvent) { alert("Event " + theEvent.type + " for element " + theEvent.target.nodeName); }
<button dojoType="dijit.form.Button" onclick="showEvent">OK</button>
Write the handler method as shown in bold face below:
<button dojoType="dijit.form.Button" onclick="showEvent">Cancel</button>
<script type="text/javascript">
dojo.require("dijit.form.DateTextBox"); dojo.require("dijit.form.ComboBox"); dojo.require("dijit.form.CheckBox"); dojo.require("dijit.form.Button"); function showEvent(theEvent) { alert("Event: " + theEvent.type + " for element: " + theEvent.target.nodeName); } </script> |